package ch01;

/**
 * Implement a function void reverse(char* str) in C or C++ which reverses a 
 * null-terminated string.
 * @author Xi Chen
 *
 */

public class Reverse_02 {
	
	public static void reverse(char[] str) {
		int size = 0;
		for (int i = 0; ; i++) {
			if (str[i] == '\0') {
				size = i;
				break;
			}
		}
		int mid = size / 2;
		char temp;
		for (int i = 0; i < mid; i++) {
			temp = str[i];
			str[i] = str[size - 1 - i];
			str[size - 1 - i] = temp;
		}
	}

	public static void main(String[] args) {
		char[] str = {'a', 'b', '1', 'a', 'Z', 'Y', '\0'};
		//System.out.println(str.length);
		reverse(str);
//		for (int i = 0; i < str.length - 1; i ++) {
//			System.out.print(str[i]);
//		}
		System.out.println(str);
	}

}
